const seatsDao = require('../dao/seatsDao');

module.exports = {
  //查询
  async Allseatss() {
    return await seatsDao.Allseats()
  },
  //查询完整信息
  async completeInformation(seatsId) {
    return await seatsDao.completeInformation(seatsId)
  },
  //选择位置、场次
  async checkIn({
    row,
    col,
    displayName,
    theaterId
  }) {
    let result = await seatsDao.queryToRepeat({
      row,
      col
    });
    if (result != null) {
      return ({
        code: '0',
        msg: '座位不可选'
      })
    } else {
      await seatsDao.seatsData({
        row,
        col,
        displayName,
        theaterId
      });
      return ({
        code: '1',
        msg: '座位可选'
      })
    }
  },
  //修改位置、场次
  async modifyOption({
    '_id': seatsid
  }, {
    row,
    col,
    displayName,
    theaterId
  }) {
    return await seatsDao.modifySeats({
      '_id': seatsid
    }, {
      row,
      col,
      displayName,
      theaterId
    })
  },
  //删除位置、场次
  async deleteSelectedSeat(seatsid) {
    return await seatsDao.deleteSeats({
      '_id': seatsid
    })
  },
    //分页
    async getAccessToPag({currentpage,pagesize}){
      //创建一个空对象
     let pagedata={};
     //当前页数
     pagedata.currentpage=currentpage;
      //每页显示的条数
     pagedata.pagesize=pagesize;
     //显示的数据
     pagedata.data=await seatsDao.accessToPag({currentpage,pagesize});
      //总条数
     pagedata.totalInt=await seatsDao.getsNumber();
     //总页数
     pagedata.totalSize=Math.ceil( pagedata.totalInt/pagesize);
     return pagedata
  },
}